<link rel="stylesheet" href="<%=request.getContextPath() %>/css/common.css">
<%@ page import="edu.xcdq.dao.impl.NewsDaoImpl" %>
<%@ page import="edu.xcdq.bean.News" %>
<%@ page import="java.util.List" %>
<%@ page import="edu.xcdq.service.NewsService" %>
<%@ page import="edu.xcdq.service.impl.NewsServiceImpl" %>
<%@ page import="edu.xcdq.util.PageSupport" %><%--
  Created by IntelliJ IDEA.
  User: huyuansong
  Date: 2021/11/2
  Time: 16:29
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>

    <%
        //获取当前页码
        String currntPage=request.getParameter("pageIndex");
        if(currntPage==null)
            currntPage="1";
        int pageIndex=Integer.parseInt(currntPage);
        //获取新闻记录总数量
        NewsService newsService = new NewsServiceImpl();
        int totalCount=newsService.getTotalCount();
        //每页显示记录数
        int pageSize=4;
        /*获取总页数*/
        PageSupport pages=new PageSupport();
        pages.setCurrentPageNo(pageIndex);
        pages.setPageSize(pageSize);
        pages.setTotalCount(totalCount);
        int totalPage=pages.getTotalPageCount();

        //控制首页和末页
        if(pageIndex<1)
            pageIndex=1;
        else if(pageIndex>totalPage)
            pageIndex=totalPage;

        //每页显示的新闻列表
        List<News> newsList=newsService.getPageNews(pageIndex, pageSize);


    %>
    <form name ="searchForm" id="searchForm" action="/news/jsp/admin/index.jsp" method="post">
        <div>
            新闻分类：
            <select name="categoryId">
                <option value="0">全部</option>

                <option value='1' >国内</option>

                <option value='2' >国际</option>

                <option value='3' >娱乐</option>

                <option value='4' >军事</option>

                <option value='5' >财经</option>

                <option value='6' >天气</option>

            </select>
            新闻标题<input type="text" name="title" id="title" value=''/>
            <button type="submit" class="page-btn">GO</button>
            <button type="button" onclick="addNews();" class="page-btn">增加</button>
            <input type="hidden" name="currentPageNo" value="1"/>
            <input type="hidden" name="pageSize" value="10"/>
            <input type="hidden" name="totalPageCount" value="2"/>
        </div>
    </form>
    <table cellpadding="1" cellspacing="1" class="admin-list">
        <thead >
        <tr class="admin-list-head">
            <th>新闻标题</th>
            <th>作者</th>
            <th>摘要</th>
            <th>内容</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <%
            Integer i = 0;
            for(News news:newsList){
                i++;
        %>
        <tr <%if(i%2==0){ %>class="admin-list-td-h2"<%} %>>
            <td><a href='index.jsp?id=<%=news.getId()%>'><%=news.getTitle() %></a></td>
            <td><%=news.getAuthor() %></td>
            <td><%=news.getSummary() %></td>
            <td><%=news.getContent() %></td>
            <td><a href='adminNewsCreate.jsp?id=2'>修改</a>
                <a href="javascript:if(confirm('确认是否删除此新闻？')) location='adminNewsDel.jsp?id=2'">删除</a>
            </td>
        </tr>
        <%} %>
        </tbody>
        <div class="page-bar">
            <ul class="page-num-ul clearfix">
                <li>共<%=totalCount %>条记录&nbsp;&nbsp; <%=pageIndex %>/<%=totalPage %>页</li>
                <%
                    if(pageIndex>1){
                %>
                <a href="index.jsp?pageIndex=1">首页</a>
                <a href="index.jsp?pageIndex=<%=pageIndex-1%>">上一页</a>
                <%}if(pageIndex<totalPage){ %>
                <a href="index.jsp?pageIndex=<%=pageIndex+1%>">下一页</a>
                <a href="index.jsp?pageIndex=<%=totalPage%>">最后一页</a>
                <%} %>&nbsp;&nbsp;
            </ul>
            <span class="page-go-form"><label>跳转至</label>
	     <input type="text" name="inputPage" id="inputPage" class="page-key" />页
	     <button type="button" class="page-btn" onClick='jump_to(document.forms[0],document.getElementById("inputPage").value)'>GO</button>
		</span>
        </div>

    </table>


</body>
</html>
